/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package data;

import java.io.Serializable;
import java.util.ArrayList;
import javax.swing.text.StyledEditorKit;

/**
 *
 * @author GREENWIND
 */
public class Row implements Serializable {
    private ArrayList<Cell> listCell;
    private int nCell;
    private int id;
    public Row(ArrayList<Cell> _list, int _nCell, int _id){
        listCell = _list;
        nCell = _nCell;
        id = _id;
    }
    public Row(Row other){
        this.nCell = other.getnCell();
        this.id = other.id;
        this.listCell = new ArrayList<>();
        
        for(int i=0; i<nCell; i++){
            this.listCell.add(other.getListCell().get(i));
        }
    }
    public Row(){
        listCell = new ArrayList<Cell> ();
        nCell = 0;
        id = -1;
    }
    
    /**
     * delete cell
     * @param posCell
     * @return 
     */
    public Boolean deleteCell(int posCell) {
        try {
            listCell.remove(posCell);
            return true;
        } catch (Exception e) {
            System.out.println(e.toString());
            return false;
        }
    }
    
    /**
     * them list cac danh sach cell o cuoi dong
     * @param cells
     * @return 
     */
    public Boolean appendCell(ArrayList<Cell> cells){
        for(int i=0; i<cells.size(); i++){
           if( !this.listCell.add(cells.get(i)))
               return false;
        }
        return true;
    }
    public Boolean setCell(Cell cell){
        return listCell.add(cell);
    }
    public Cell  getCell(String cellName){
        for(int i =0; i<listCell.size(); i++){
            if(listCell.get(i).getName().equals(cellName)){
                return listCell.get(i);
            }
        }
        return null;
    }

    /**
     * xoa het du lieu tren dong
     * @return 
     */
    public void Clear(){
        listCell.clear();
        nCell = 0;
    }
    /**
     * @return the listCell
     */
    public ArrayList<Cell> getListCell() {
        return listCell;
    }

    /**
     * @param listCell the listCell to set
     */
    public void setListCell(ArrayList<Cell> listCell) {
        this.listCell = listCell;
    }

    /**
     * @return the nCell
     */
    public int getnCell() {
        return nCell;
    }
    public void setnCell(int nCell){
        this.nCell = nCell;
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }
}
